package core

import (
	lru "github.com/hashicorp/golang-lru/v2"
)

type Cache struct {
	cache *lru.TwoQueueCache[string, []byte]
}

// initCache initializes the cache
func (gj *graphjinEngine) initCache() (err error) {
	gj.cache.cache, err = lru.New2Q[string, []byte](500)
	return
}

// Get returns the value from the cache
func (c Cache) Get(key string) (val []byte, fromCache bool) {
	val, fromCache = c.cache.Get(key)
	return
}

// Set sets the value in the cache
func (c Cache) Set(key string, val []byte) {
	c.cache.Add(key, val)
}
